package com.hd.determine.core.thread;

import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.task.TaskExecutor;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

import java.util.concurrent.ThreadPoolExecutor;

/**
 * @author chentl
 * @version V1.0
 * @Project 交通运输第三方监测平台
 * @Title StatisticTaskExecutePool.java
 * @Description 处理统计任务的线程池
 * @Package com.hd.sup.core.thread
 * @date 2020/12/24 11:01 上午
 * @Copyright: 深圳市宏电技术股份有限公司 All rights reserved.
 */
@Slf4j
@Configuration
public class DetermineTaskExecutePool {


    //自定义线程池
    @Bean(name = "determineTaskExecutor")
    public TaskExecutor statisticTaskExecutor() {
        log.info("[determine] 准备创建 determineTaskExecutor 线程池");
        ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor();
        taskExecutor.setCorePoolSize(5);
        taskExecutor.setMaxPoolSize(10);
        taskExecutor.setQueueCapacity(40);
        taskExecutor.setKeepAliveSeconds(200);
        taskExecutor.setThreadNamePrefix("AsyncDeterminer-");
        taskExecutor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
        taskExecutor.setWaitForTasksToCompleteOnShutdown(true);
        taskExecutor.setAwaitTerminationSeconds(60);
        taskExecutor.initialize();
        log.info("[determine] determineTaskExecutor 线程池创建成功!");
        return taskExecutor;
    }
}
